package com.campus.controller;

import com.campus.common.JWTUtil;
import com.campus.common.core.Result;
import com.campus.common.core.TableData;
import com.campus.model.TSysUser;
import com.campus.model.dto.TCourseLearnUnitCreateDto;
import com.campus.model.vo.TCourseLearnUnitSelectVo;
import com.campus.service.ILearnUnitService;
import com.campus.service.ISysUserService;
import com.campus.service.IUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/learnUnit")
@Api(tags = "学习单元管理")
public class LearnUnitController {

    @Autowired
    private ILearnUnitService learnUnitService;

    @PostMapping("/create")
    @ApiOperation("创建学习单元")
    public Result<Integer> createLearnUnit(@RequestBody @Validated TCourseLearnUnitCreateDto unitCreateDto) {
        return Result.success(learnUnitService.createLearnUnit(unitCreateDto));
    }

    @GetMapping("/getLearnUnitList")
    @ApiOperation("获取学习单元列表")
    public TableData<TCourseLearnUnitSelectVo> getLearnUnitList(@RequestParam Long courseId) {
        List<TCourseLearnUnitSelectVo> learnUnitByCourseId = learnUnitService.getLearnUnitByCourseId(courseId);
        return TableData.success(learnUnitByCourseId, Long.valueOf(learnUnitByCourseId.size()));
    }
}